#include "packet_2_0.h"
#include "player.h"
#include "monster.h"
#include "item.h"

void PacketPlayerData::pack (Player& pl)
{
		uid = pl.getUID();
		name = pl.getName() ;
		x = pl.getX() ;
		y = pl.getY() ;
		hp = pl.data.getHP() ;
		mp = pl.data.getMP() ;
		meshID = pl.meshID ;
}

void PacketPlayerData::unpack (Player& pl)
{
	pl.setID(uid);
	pl.setName(name);
	pl.setXY(x,y) ;	
	//pl.data.setData(hp,mp) ;
	pl.data.setHP(hp) ;
	pl.data.setMP(mp) ;
	pl.meshID = meshID ;
			
}

PacketPlayerData::PacketPlayerData ():BasePacket (ID_PKT_PLAYER_DATA)
{
}



void PacketMainPlayerData::pack( Player& pl )
{
	
	name = pl.getName() ;
	uid = pl.getUID() ;
	x = pl.getX() ;
	y = pl.getY() ;
	hp = pl.data.getHP() ;
	mp = pl.data.getMP() ;
	max_hp = pl.data.getTotalMaxHP() ;
	max_mp = pl.data.getTotalMaxMP() ;
	exp = pl.data.getEXP() ;
	level = pl.data.getlevel() ;
	meshID = pl.meshID ;
	
}

void PacketMainPlayerData::unpack ( Player& pl)
{
	pl.setID(uid) ;	
	pl.setXY(x , y) ;	
	pl.data.setTotalHPMP(max_hp,max_mp) ;
	pl.data.setHP(hp) ;
	pl.data.setMP(mp) ;
	pl.data.setEXP(exp) ;
	pl.data.setlevel(level) ;
	pl.setName(name) ;
	pl.meshID = meshID ;
}

PacketMainPlayerData::PacketMainPlayerData():BasePacket (ID_PKT_MAINPLAER_DATA)
{
}
void PacketMonsterData::pack (Monster& m) 
{	
	name = m.getName() ;
	uid = m.getUID() ;	
	tx = m.get_TargetX();
	ty = m.get_TargetY() ;
	x = m.getX() ;
	y = m.getY() ;
	speed = m.getSpeed();
	monsterID = m.getID();	 

}
void PacketMonsterData::unpack (Monster& m) 
{	
	
	m.setID(uid) ;
	m.setSpeed(speed);
	m.setTarget(tx,ty) ;	
	m.setXY(x,y);
	m.setName(name) ;
	
}
PacketMonsterData::PacketMonsterData () :BasePacket(ID_PKT_MONSTER_DATA)
{

}
void PacketMainPlayerDataWG::pack (int nid, Player& pl )
{
	netPlayerID = nid ;
	uid = pl.getUID() ;
	name = pl.getName() ;
	x = pl.getX() ;
	y = pl.getY() ;	
	hp = pl.data.getHP() ;
	mp = pl.data.getMP() ;
	max_hp = pl.data.getTotalMaxHP();
	max_mp = pl.data.getTotalMaxMP();
	meshID = pl.meshID ;
	
}

void PacketMainPlayerDataWG::unpack (Player& pl,Team&tm)
{	
	
	pl.setID(uid) ;
	pl.setName(name) ;	
	pl.setXY(x,y) ;	
	pl.data.setHP(hp) ;
	pl.data.setMP(mp) ;
	pl.data.setTotalHPMP(max_hp,max_mp) ;
	tm = team ;
	pl.meshID = meshID ;

	
}

PacketMainPlayerDataWG::PacketMainPlayerDataWG ():BasePacket (ID_PKT_MAIN_PLAYER_DATA_WG)
{
}

void PacketBackpackItem::pack (Item& item, int pos)
{
	offset = pos ;
	itemID = item.getID () ;
	stack = item.getStack () ;
	
}

void PacketBackpackItem::unpack (Backpack& bp)
{	
	bp.setItem(itemID,stack,offset) ;
}
PacketBackpackItem::PacketBackpackItem ():BasePacket (ID_PKT_BACKPACK_ITEM)
{
}








void PacketChestItem::pack (Item& item, int pos)
{
	offset = pos ;
	itemID = item.getID () ;
	
	stack = item.getStack () ;
	
}

void PacketChestItem::unpack (Backpack&bp)
{	
	Item item;
	bp.setItem(itemID,offset,stack) ;	
}
PacketChestItem::PacketChestItem ():BasePacket (ID_PKT_CHEST_ITEM)
{
}







